assert_that(p.cargo("doc"),
execs().with_status(0).with_stderr(&format!("\
-[..] foo v0.0.1 ({dir})
+[DOCUMENTING] foo v0.0.1 ({dir})
[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
", dir = path2url(p.root()))));
assert_that(&p.root().join("target/doc"), existing_dir());
assert!(!doc_html.contains("Binary"));
}
+#[test]
+fn doc_lib_bin_same_name_documents_lib_when_requested() {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/main.rs", r#"
+ //! Binary documentation
+ extern crate foo;
+ fn main() {
+ foo::foo();
+ }
+ "#)
+ .file("src/lib.rs", r#"
+ //! Library documentation
+ pub fn foo() {}
+ "#)
+ .build();
+
+ assert_that(p.cargo("doc").arg("--lib"),
+ execs().with_status(0).with_stderr(&format!("\
+[DOCUMENTING] foo v0.0.1 ({dir})
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+", dir = path2url(p.root()))));
+ assert_that(&p.root().join("target/doc"), existing_dir());
+ let doc_file = p.root().join("target/doc/foo/index.html");
+ assert_that(&doc_file, existing_file());
+ let mut doc_html = String::new();
+ File::open(&doc_file).unwrap().read_to_string(&mut doc_html).unwrap();
+ assert!(doc_html.contains("Library"));
+ assert!(!doc_html.contains("Binary"));
+}
+
+#[test]
+fn doc_lib_bin_same_name_documents_named_bin_when_requested() {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/main.rs", r#"
+ //! Binary documentation
+ extern crate foo;
+ fn main() {
+ foo::foo();
+ }
+ "#)
+ .file("src/lib.rs", r#"
+ //! Library documentation
+ pub fn foo() {}
+ "#)
+ .build();
+
+ assert_that(p.cargo("doc").arg("--bin").arg("foo"),
+ execs().with_status(0).with_stderr(&format!("\
+[COMPILING] foo v0.0.1 ({dir})
+[DOCUMENTING] foo v0.0.1 ({dir})
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+", dir = path2url(p.root()))));
+ assert_that(&p.root().join("target/doc"), existing_dir());
+ let doc_file = p.root().join("target/doc/foo/index.html");
+ assert_that(&doc_file, existing_file());
+ let mut doc_html = String::new();
+ File::open(&doc_file).unwrap().read_to_string(&mut doc_html).unwrap();
+ assert!(!doc_html.contains("Library"));
+ assert!(doc_html.contains("Binary"));
+}
+
+#[test]
+fn doc_lib_bin_same_name_documents_bins_when_requested() {
+ let p = project("foo")
+ .file("Cargo.toml", r#"
+ [package]
+ name = "foo"
+ version = "0.0.1"
+ authors = []
+ "#)
+ .file("src/main.rs", r#"
+ //! Binary documentation
+ extern crate foo;
+ fn main() {
+ foo::foo();
+ }
+ "#)
+ .file("src/lib.rs", r#"
+ //! Library documentation
+ pub fn foo() {}
+ "#)
+ .build();
+
+ assert_that(p.cargo("doc").arg("--bins"),
+ execs().with_status(0).with_stderr(&format!("\
+[COMPILING] foo v0.0.1 ({dir})
+[DOCUMENTING] foo v0.0.1 ({dir})
+[FINISHED] dev [unoptimized + debuginfo] target(s) in [..]
+", dir = path2url(p.root()))));
+ assert_that(&p.root().join("target/doc"), existing_dir());
+ let doc_file = p.root().join("target/doc/foo/index.html");
+ assert_that(&doc_file, existing_file());
+ let mut doc_html = String::new();
+ File::open(&doc_file).unwrap().read_to_string(&mut doc_html).unwrap();
+ assert!(!doc_html.contains("Library"));
+ assert!(doc_html.contains("Binary"));
+}
+
#[test]
fn doc_dash_p() {
let p = project("foo")